<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="js/vue.js"></script>
</head>
<body>
    <div id="app">
        <p>{{ msg }}</p>
        <p>{{ msg2 }}</p>
        <hr>

        <p>{{ sex }}</p>
        <button @click="sex='女'">修改sex</button>
        <hr>

        <p>{{ user.name }}</p>
        <button @click="user.name='alice'">修改user.name</button>

    </div>

    <script>
        new Vue({
            el: '#app',
            data: { // 普通属性
                msg: 'welcome to wanho',
                sex: '男',
                user: {
                    id: 1001,
                    name: 'tom',
                    age: 20
                }
            },
            computed: { // 计算属性
                msg2(){
                    // 基于普通属性，进行处理计算，返回处理后的结果
                    return this.msg.toUpperCase().split(' ').reverse().join(' ')
                }
            },
            watch: {
                sex: function(newValue, oldValue){
                    console.log(newValue, oldValue)
                },
                user: {
                    handler: function(newUser, oldUser){
                        console.log(newUser, oldUser)
                    },
                    deep: true // 监听对象属性的变化
                }
            }
        })
    </script>
</body>
</html>